package com.sound.ampache;

/* Copyright (c) 2010 Brian Kirkman <kirkman.brian@gmail.com>
*
* +------------------------------------------------------------------------+
* | This program is free software; you can redistribute it and/or          |
* | modify it under the terms of the GNU General Public License            |
* | as published by the Free Software Foundation; either version 3         |
* | of the License, or (at your option) any later version.                 |
* |                                                                        |
* | This program is distributed in the hope that it will be useful,        |
* | but WITHOUT ANY WARRANTY; without even the implied warranty of         |
* | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          |
* | GNU General Public License for more details.                           |
* |                                                                        |
* | You should have received a copy of the GNU General Public License      |
* | along with this program; if not, write to the Free Software            |
* | Foundation, Inc., 59 Temple Place - Suite 330,                         |
* | Boston, MA  02111-1307, USA.                                           |
* +------------------------------------------------------------------------+
*
* Special thanks to the following: 
* Kevin Purdy, author of Amdroid, for much of the code used in this project
* 
* Jorge Ramon, author of MiamiCoder blog, for many great BlackBerry examples
* published on his blog.
* 
* 
*/

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Characters;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.ObjectListField;
import net.rim.device.api.ui.container.MainScreen;


class ItemsScreen extends MainScreen {
	
	protected Dialog statusDlg;
	protected int fontSize;
	protected int rowHeight;
	protected static ObjectListField itemsList = new ObjectListField();
	
    Font mainFont = Font.getDefault().derive(Font.PLAIN, 24);
    
	ItemsScreen()
	{		
		setFont(mainFont);
        setRowHeight();
        Bitmap icon = Bitmap.getBitmapResource("img/download.png"); 
        statusDlg = new Dialog("Downloading...",null,null,0,icon); 
	}
	
	
	public void setRowHeight() {
		//Get user selected font size and set screen font sizes
		fontSize = Integer.parseInt(DataStore.getFontSize());
		rowHeight = fontSize * 3 + 5;
        itemsList.setRowHeight(rowHeight);
        itemsList.setFont(Font.getDefault().derive(Font.PLAIN, fontSize));
	}
    
    
    //Allows space bar to page down, T to top, B to bottom
    //N to Next(5 pages down), P to previous (5 pages up)
    public boolean keyChar(char key, int status, int time) {
        if (itemsList.getSize() > 0) {
	        switch (key) {
	        case Characters.SPACE:
	        	getScreen().scroll(Manager.DOWNWARD);
	        	return true;
	        case Characters.LATIN_SMALL_LETTER_T:
	        	getScreen().scroll(Manager.TOPMOST);
	        	return true;
	        case Characters.LATIN_SMALL_LETTER_B:
	        	getScreen().scroll(Manager.BOTTOMMOST);
	        	return true;
	        case Characters.LATIN_SMALL_LETTER_N:
	        	getScreen().scroll(Manager.DOWNWARD);
	        	getScreen().scroll(Manager.DOWNWARD);
	        	getScreen().scroll(Manager.DOWNWARD);
	        	getScreen().scroll(Manager.DOWNWARD);
	        	getScreen().scroll(Manager.DOWNWARD);
	        	return true;
	        case Characters.LATIN_SMALL_LETTER_P:
	        	getScreen().scroll(Manager.UPWARD);
	        	getScreen().scroll(Manager.UPWARD);
	        	getScreen().scroll(Manager.UPWARD);
	        	getScreen().scroll(Manager.UPWARD);
	        	getScreen().scroll(Manager.UPWARD);
	        	return true;
	        }
        }
        return super.keyChar(key, status, time);
    }
    
    
} 
